// 函数组件
import { EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
import { useState, useEffect, useContext, useRef } from 'react';

import { message, Button, Form, Input, } from 'antd';


import '../../css/AccountSetting.css'
import { getSetUser } from "@/api/index1";


function AccountSetting() {
    const [userInfo, setUserInfo] = useState<any>()



    useEffect(() => {
        // console.log("ffff", JSON.parse(sessionStorage.getItem('userInfo')))
        let user = JSON.parse(sessionStorage.getItem('userInfo') || '{}')
        setUserInfo(user)
    }, [])





    const [form] = Form.useForm();//使用From表单，用于默认值

    const userInfoData = async (values: any) => {
        // console.log(values);

        const data = ({
            admin: values.admin,
            email: values.email,
            name: values.name,
            newPassword: values.newPassword,
            oldPassword: values.oldPassword,
            phone: values.phone,

        })
        try {
            let res = await getSetUser(data)
            // console.log(res);

            if (res.code == '200') {
                console.log('修改数据成功', res.data);

            }
        } catch (err) {
            console.log('修改数据失败', err);

        }

        form.resetFields()
        message.success('提交成功！')
    };
    return (
        <div className='AccountSetting'>
            <div className='AccountSetting-1'>
                <p>账号设置</p>
            </div>



            <div className='Form1'>
                <h3>账号信息设置</h3>

                <Form
                    form={form}
                    onFinish={userInfoData}
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 14 }}
                    layout="horizontal"

                    style={{ maxWidth: 600 }}
                >

                    <Form.Item label="账号" name='admin'>
                        <Input placeholder={userInfo?.emplNumber} />
                    </Form.Item>
                    <Form.Item label="角色" name='{role}'>
                        <Input placeholder={userInfo?.roleName} disabled />
                    </Form.Item>
                    <Form.Item label="姓名" name='name'>
                        <Input placeholder={userInfo?.emplName} />
                    </Form.Item>
                    <Form.Item label="邮箱" name='email'>
                        <Input placeholder="请输入邮箱" />
                    </Form.Item>

                    <Form.Item label="手机号" name='phone'>
                        <Input placeholder="请输入手机号" />
                    </Form.Item>
                    <Form.Item label="旧密码" name='oldPassword'>
                        <Input.Password
                            placeholder="请输入旧密码"
                            iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
                        />
                    </Form.Item>
                    <Form.Item label="新密码" name='newPassword'>
                        <Input.Password
                            placeholder="请输入新密码"
                            iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
                        />
                    </Form.Item>
                    <Form.Item label="确认密码" name='password'>

                        <Input.Password
                            placeholder="请确认密码"
                            iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
                        />

                    </Form.Item>



                    <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                        <Button type="primary" htmlType="submit">
                            提交
                        </Button>
                    </Form.Item>
                </Form>
            </div>



        </div>
    )
}

export default AccountSetting